package com.vienlien247.vienlien247;

import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewConfiguration;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.TextView;

import java.lang.reflect.Field;

public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getOverflowMenu();

        TextView tv_pinless = (TextView) findViewById(R.id.tv_pinless);
        TextView tv_mobile = (TextView) findViewById(R.id.tv_mobile);
        TextView tv_uno = (TextView) findViewById(R.id.tv_uno);

        tv_pinless.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                WebView wv = new WebView(MainActivity.this);
                wv.setWebChromeClient(new WebChromeClient());
                wv.loadUrl("http://vienlien247.com/nap-tien-v247-online");
                wv.setBackgroundColor(0x00000000);
                wv.getSettings().setLoadsImagesAutomatically(true);
            }
        });

        tv_mobile.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                WebView wv = new WebView(MainActivity.this);
                wv.setWebChromeClient(new WebChromeClient());
                wv.loadUrl("http://vienlien247.com/mua-phut-v247-mobile");
                wv.setBackgroundColor(0x00000000);
                wv.getSettings().setLoadsImagesAutomatically(true);
            }
        });

        tv_uno.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                WebView wv = new WebView(MainActivity.this);
                wv.setWebChromeClient(new WebChromeClient());
                wv.loadUrl("http://vienlien247.com/mua-uno-ip-box");
                wv.setBackgroundColor(0x00000000);
                wv.getSettings().setLoadsImagesAutomatically(true);
            }
        });
    }

    //region action bar
    @Override
    public boolean onOptionsItemSelected(MenuItem menuItem) {
        switch (menuItem.getItemId()) {
            case android.R.id.home:
                onBackPressed();
                return true;
            case R.id.action_home:
                Intent homepage = new Intent(this, MainActivity.class);
                startActivity(homepage);
                return true;

        }
        return (super.onOptionsItemSelected(menuItem));
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    private void getOverflowMenu() {

        try {
            ViewConfiguration config = ViewConfiguration.get(this);
            Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
            if (menuKeyField != null) {
                menuKeyField.setAccessible(true);
                menuKeyField.setBoolean(config, false);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    //endregion
}
